home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dskut
/
reform15.zip
/
REFORMAT.IN1
< prev
next >
Wrap
Text File
|
1987-05-23
|
6KB
|
206 lines
{REFORMAT IN1}
{
Unsigned word arithmetic routines.
Just to have the source of the program clean, and free of dirty tricks.
Some of the functions provided here are redundant, e.g. the shift
functions, since TURBO's shift functions are logical shifts, rather
than arithmetic shifts.
Functions:
W_not(W1 : word): word; bitwise logical not
W_add(W1, W2 : word): word; addition
W_sub(W1, W2 : word): word; subtraction
W_or (W1, W2 : word): word; bitwise logical or
W_xor(W1, W2 : word): word; bitwise logical xor
W_mul(W1, W2 : word): word; multiplication
W_div(W1, W2 : word): word; division (W1/W2)
W_mod(W1, W2 : word): word; modulus
W_and(W1, W2 : word): word; bitwise logical and
W_shl(W1 : word, Shift : integer): word; logical leftshift
W_shr(W1 : word, Shift : integer): word; logical rightshift
I_wrd(W1 : word): integer word to integer conversion
W_int(I1 : integer): word integer to word conversion
W_cmp(W1 : word, Op : Relational_Operator, W2 : word): boolean;
with Relational_Operator =
(Eq, Gt, Lt, Ne, Ge, Le.)
}
FUNCTION W_not(W1 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$F7/$D0/ { not ax }
$89/$46/$06 { mov [bp+6],ax }
);
END;
FUNCTION W_add(W1, W2 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$03/$86/W2/ { add ax,W2[bp] }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION W_sub(W1, W2 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$2B/$86/W2/ { sub ax,W2[bp] }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION W_or (W1, W2 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$0B/$86/W2/ { or ax,W2[bp] }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION W_xor(W1, W2 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$33/$86/W2/ { xor ax,W2[bp] }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION W_mul(W1, W2 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$F7/$A6/W2/ { mul W2[bp] }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION W_div(W1, W2 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$99/ { cwd }
$F7/$B6/W2/ { div W2[bp] }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION W_mod(W1, W2 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$99/ { cwd }
$F7/$B6/W2/ { div W2[bp] }
$89/$56/$08 { mov [bp+8],dx }
);
END;
FUNCTION W_and(W1, W2 : word): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$23/$86/W2/ { and ax,W2[bp] }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION W_shl(W1 : word; Shift : INTEGER): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$8B/$8E/Shift/ { mov cx,Shift[bp] }
$D3/$E0/ { shl ax,cl }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION W_shr(W1 : word; Shift : INTEGER): word;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$8B/$8E/Shift/ { mov cx,Shift[bp] }
$D3/$E8/ { shr ax,cl }
$89/$46/$08 { mov [bp+8],ax }
);
END;
FUNCTION I_wrd(W1 : word): INTEGER;
BEGIN
InLine(
$8B/$86/W1/ { mov ax,W1[bp] }
$89/$46/$06 { mov [bp+6],ax }
);
END;
FUNCTION W_int(I1 : INTEGER): word;
BEGIN
InLine(
$8B/$86/I1/ { mov ax,I1[bp] }
$89/$46/$06 { mov [bp+6],ax }
);
END;
FUNCTION W_cmp(W1 : word; Operator : Relational_Operator; W2 : word): BOOLEAN;
BEGIN
InLine(
$8B/$86/>W1 { mov ax,>W1[bp]}
/$8B/$96/>W2 { mov dx,>W2[bp]}
/$31/$C9 { xor cx,cx ;clear msb}
/$31/$DB { xor bx,bx ;assume false}
/$8A/$4E/$06 { mov cl,[bp+6] ;snarf the operator}
/$09/$C9 { or cx,cx ;Eq?}
/$74/$16 { je Eq ; yep}
/$80/$F9/$01 { cmp cl,1 ;Gt?}
/$74/$17 { je Gt ; yep}
/$80/$F9/$02 { cmp cl,2 ;Lt?}
/$74/$18 { je Lt ; yep}
/$80/$F9/$03 { cmp cl,3 ;Ne?}
/$74/$19 { je Ne ; yep}
/$80/$F9/$04 { cmp cl,4 ;Ge?}
/$74/$1A { je Ge ; yep}
/$EB/$1E { jmp short Le ; must be Le}
{Eq:}
/$39/$D0 { cmp ax,dx}
/$75/$1F { jne False}
/$EB/$1C { jmp short True}
{Gt:}
/$39/$D0 { cmp ax,dx}
/$7E/$19 { jle False}
/$EB/$16 { jmp short True}
{Lt:}
/$39/$D0 { cmp ax,dx}
/$73/$13 { jae False}
/$EB/$10 { jmp short True}
{Ne:}
/$39/$D0 { cmp ax,dx}
/$74/$0D { je False}
/$EB/$0A { jmp short True}
{Ge:}
/$39/$D0 { cmp ax,dx}
/$72/$07 { jb False}
/$EB/$04 { jmp short True}
{Le:}
/$39/$D0 { cmp ax,dx}
/$77/$01 { ja False}
{True:}
/$43 { inc bx ;make it true}
{False: ;just stuff the 0}
/$88/$5E/$0A { mov [bp+$0A],bl}
{Exeunt: ;and let Turbo do the rest}
);
END; {of W_cmp}